#include<bits/stdc++.h>
using namespace std;

int a[1100];

int main()
{
	int t, ques, n;
	cin>>t;
	while(t--)
	{
		memset(a, 0, sizeof a);
		cin>>n>>ques;
		for(int i = 1;i <= n;i++)
			cin>>a[i];
		while(ques--)
		{
			int op, h;
			cin>>op>>h;
			
			if(op == 1)
			{
				int hh = upper_bound(a+1, a+n+1, h)-a;
				if(hh > n)
					cout<<"-1"<<endl;
				else
					cout<<a[hh]<<endl;
			}
			else
			{
				int hh = lower_bound(a+1, a+n+1, h)-a;
				if(h == a[hh])
					cout<<a[hh]<<endl;
				else
				{
					if(hh != 1)
						cout<<a[hh-1]<<endl;
					else
						cout<<"-1"<<endl; 
				}
			}
		}
	}
	return 0;
}

